<!--
 * @author luguoxiang
 * @date 2022/9/17
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
-->
<template>
  <lg-modal ref="containerRef" header="修改密码" width="500px" mode="modeless" draggable @confirm="ok">
    <div class="gl-form">
      <lg-form ref="formRef" :schema="updatePasswordForm" :data="data" />
    </div>
  </lg-modal>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { LgForm, LgModal } from '@/soar';
import { updatePasswordForm } from './schema';
import api from './api';

const emits = defineEmits(['ok']);
const containerRef = ref();
const formRef = ref();
const data = ref({});
const ids = ref([]);

/**
 * 点击确定时
 */
function ok() {
  formRef.value.validate().then((values: any) => {
    api.updatePassword(ids.value, values.password).then(() => {
      formRef.value.reset();
      containerRef.value.close();
      emits('ok', values);
    });
  });
}

defineExpose({
  open(params: any) {
    ids.value = params;
    containerRef.value.open();
  },
});
</script>
